<?php

namespace App\Http\Controllers;

use App\Destination;
use App\Flight;
use App\User;
use Illuminate\Http\Request;

class TestController extends Controller
{
    public function test001() {
        $users = User::cursor()->filter(function ($user) {
            return $user->id > 1;
        });

        foreach ($users as $user) {
            dump($user->id);
        }
    }

    public function test002() {
        /*$result = Destination::addSelect(['last_flight' => Flight::select('f_name')
            ->whereColumn('destination_id', 'destinations.id')
            ->orderBy('arrived_at', 'desc')
            ->limit(1)
        ])->get();*/

        /*$result = Destination::select(['last_flight' => Flight::select('f_name')
            ->whereColumn('destination_id', 'destinations.id')
            ->orderBy('arrived_at', 'desc')
            ->limit(1)
        ])->get();*/

        $result = Destination::orderByDesc(
            Flight::select('arrived_at')
                ->whereColumn('destination_id', 'destinations.id')
                ->orderBy('arrived_at', 'desc')
                ->limit(1)
        )->get();

        dd($result);
    }

    public function test003() {
        $query = \DB::table('users')->select(['ddid' => 'id','name as eee']);
        $result = $query->addSelect(['aa' => 'email'])->get();

        dd($result);
    }
}
